//
//  GGZFBMineViewController.m
//  Gunterapple
//
//  Created by 热带雨林 on 2020/4/1.
//  Copyright © 2020 热带雨林. All rights reserved.
//

#import "GGZFBMineViewController.h"
#import "ZFBOptionModel.h"
#import "GGAddtion.h"
#import "GGZFBOptionFlowlayout.h"
#import "GGZFBOptionNomarlCell.h"
#import "AGZFBOptionSecoundCell.h"
#import "GGThirdCell.h"
#define firstCount 4
#define secondCount 4
#define thirdCount 6
@interface GGZFBMineViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,AGOptionSecoundCellDelegate>
@property (nonatomic, strong) NSMutableArray <ZFBOptionModel *>*dataList;
@property (nonatomic, strong) UICollectionView *collectionView;
@end
static NSString *cellID = @"cellID";
static NSString *normalID = @"normalID";
static NSString *secoundID = @"secoundID";
static NSString *thirdID = @"thirdID";
@implementation GGZFBMineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的";
    [self loadData];
    [self setUI];
}
- (void)setUI{
    
    GGZFBOptionFlowlayout *layout = [[GGZFBOptionFlowlayout alloc]init];
    UICollectionView *collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)) collectionViewLayout:layout];
    self.collectionView = collection;
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectionView];
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:cellID];
    [self.collectionView registerClass:[GGZFBOptionNomarlCell class] forCellWithReuseIdentifier:normalID];
    [self.collectionView registerClass:[AGZFBOptionSecoundCell class] forCellWithReuseIdentifier:secoundID];
    [self.collectionView registerClass:[GGThirdCell class] forCellWithReuseIdentifier:thirdID];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 4;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    switch (section) {
        case 0:{
            return 1;
        }
            break;
        case 1:{
            return firstCount + 1;
        }
            break;
        case 2:{
            return secondCount;
        }
            break;
        case 3:{
            return thirdCount;
        }
            break;
            
        default:
            return 0;
    }
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0 && indexPath.item == 0){
        GGZFBOptionNomarlCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:normalID forIndexPath:indexPath];
        return cell;
    }else if(indexPath.section == 1 && indexPath.item == 0){
        AGZFBOptionSecoundCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:secoundID forIndexPath:indexPath];
        cell.delegate = self;
        return cell;
    }
    GGThirdCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:thirdID forIndexPath:indexPath];
    if(indexPath.section == 1)
        cell.model = self.dataList[indexPath.item -1];
    else if(indexPath.section == 2)
        cell.model = self.dataList[indexPath.item + firstCount];
    else
        cell.model = self.dataList[indexPath.item + firstCount + secondCount];
    return cell;
}
- (void)loadData{
    self.dataList = [NSArray gg_arrayModelWithPlistName:@"MineOption.plist" withClassName:@"ZFBOptionModel"].mutableCopy;
}
//此处不是UICollectionViewDelegateFlowLayout的方法 是UICollectionViewDelegate的方法
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0 && indexPath.item == 0){
        return CGSizeMake(self.view.frame.size.width, 100);
    }else if(indexPath.section == 1 && indexPath.item == 0){
        return CGSizeMake(self.view.frame.size.width, 64);
    }
    return CGSizeMake((self.view.frame.size.width - 2) / 2, 64);
}
- (void)secoundcellWithType:(NSInteger)type{
    switch (type) {
        case 1:{
            NSLog(@"1");
        }
            break;
        case 2:{
            NSLog(@"2");
        }
            break;
        case 3:{
            NSLog(@"3");
        }
            break;
        default:
            break;
    }
}

- (NSMutableArray <ZFBOptionModel *>*)dataList{
    if(!_dataList){
        _dataList = [NSMutableArray array];
    }
    return _dataList;
}

@end
